/*members getData, innerHTML, length
*/

/* Formatters */

/* begin: CompanyNameFormatter object formats data in row 'Name' */

function CompanyNameFormatter(elCell, oRecord, oColumn, oData) {

    var website, article_head, article_tail, result = '';
    if (oRecord.getData('image')) {
        result = "<img src=\"" + oRecord.getData('image') + "\" width=\"100px\" /><br />";
    }
    website = oRecord.getData('website');

    result = result + "<a href='/company" + oRecord.getData('id') + "'>" + oData + "</a>" + "<br/>";
    if (website) {
        result = result + "<a href=\"" + website + "\" title=\"Link to " + oData + " website\">" + website + "</a><br />";
    }
    article_head = oRecord.getData('article_head');
    article_tail = oRecord.getData('article_tail');
    if (article_head) {
        result = result + "<span class=\"article\">" + "<span class=\"article_head\">" + article_head + "</span>" + "<span class=\"dots\">... </span>" + "<span class=\"article_tail\" style=\"display: none;\">" + article_tail + "</span>" + "</span>";
    }
    elCell.innerHTML = result;
}
/* end: CompanyNameFormatter */

/* begin: ListFormatter object formats data as unordered list */

function ListFormatter(elCell, oRecord, oColumn, oData) {
    if ((typeof(oData) === "object") && (oData.length > 0)) {

        var SHOWED_LI = 4,
			edge_num = SHOWED_LI,
			result = "", i;
        
        if (oData.length < SHOWED_LI) {
            edge_num = oData.length;
        }

        for (i = 0; i < edge_num; i = i + 1) {
            if (oData[i]) {
                result += "<li>" + oData[i] + "</li>";
            }
        }
        if (oData.length > SHOWED_LI) {
            result += '<li class="edge"><a href="#">Show ' + oData.length + ' more...</a></li>';
        }
        for (i = edge_num; i < oData.length; i += 1) {
            if (oData[i]) {
                result += '<li class="after_edge" style="display: none;">' + oData[i] + '</li>';
            }
        }
        if (result.length > 0) {
            elCell.innerHTML = "<ul>" + result + "</ul>";
        }
    }
}
/* end: ListFormatter object formats data as unordered list */
